package ssm.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ssm.dao.CameraInfo;
import ssm.dao.Regioninfo;
import ssm.model.CameraInfoMapper;

import java.util.Map;

@Service
public class CameraInfoServiceImpl implements CameraInfoService {
    @Autowired
    private CameraInfoMapper cameraInfoMapper;

    public CameraInfo getInfoByCode(String code) {
        CameraInfo cameraInfo = cameraInfoMapper.getInfoByCode(code);
        if (cameraInfo.getXmlrev() != null) {
            cameraInfo.setXmlrev(cameraInfo.getXmlrev().replace("&", "&amp;").
                    replace("<", "&lt;").
                    replace(">", "&gt;").
                    replace("\"", "&quot;").
                    replace("'", "&apos;"));
        }
        if (cameraInfo.getPlaybackxml() != null) {
            cameraInfo.setPlaybackxml(cameraInfo.getPlaybackxml().replace("&", "&amp;").
                    replace("<", "&lt;").
                    replace(">", "&gt;").
                    replace("\"", "&quot;").
                    replace("'", "&apos;"));
        }
        if (cameraInfo.getPreviewxml() != null) {
            cameraInfo.setPreviewxml(cameraInfo.getPreviewxml().replace("&", "&amp;").
                    replace("<", "&lt;").
                    replace(">", "&gt;").
                    replace("\"", "&quot;").
                    replace("'", "&apos;"));
        }
        return cameraInfo;
    }

    public Map<String,Object> getByCameraId(int id) {
        Map<String,Object> result = cameraInfoMapper.getByCameraId(id);
        return result;
    }
}
